//文件类型缩图,注意需要有 viewImage，viewVideo，viewPdf等函数
function file_type_icon(d) {
  switch (d.file_ext) {
    case 'jpg':
    case 'png':
    case 'gif':
    case 'bmp':
    case 'ico':
      return '<a href="javascript:void(0);" onclick=viewImage("' + reurl(d.url) + '")><img class="file_table_img" src="' + reurl(d.url) + '"/></a>';
      break;
    case 'avi':
    case 'mp3':
    case 'mp4':
    case 'wav':
      return '<a href="javascript:void(0);" onclick=viewVideo("' + reurl(d.url) + '")><i class="fa fa-file-video-o file_table_i"></i></a>';
      break;
    case 'zip':
      return '<a href="javascript:void(0);"><i class="fa fa-file-zip-o file_table_i"></i></a>';
      break;
    case 'txt':
      return '<a href="javascript:void(0);"><i class="fa fa-file-text-o file_table_i"></i></a>';
      break;
    case 'doc':
    case 'docx':
      return '<a href="javascript:void(0);"><i class="fa fa-file-word-o file_table_i"></i></a>';
      break;
    case 'xls':
    case 'xlsx':
      return '<a href="javascript:void(0);"><i class="fa fa-file-excel-o file_table_i"></i></a>';
      break;
    case 'ppt':
    case 'pptx':
      return '<a href="javascript:void(0);"><i class="fa fa-file-powerpoint-o file_table_i"></i></a>';
      break;
    case 'pdf':
      return '<a href="javascript:void(0);" onclick=viewPdf("' + reurl(d.url) + '")><i class="fa fa-file-pdf-o file_table_i"></i></a>';
      break;
  }
  return '';
}

function reurl(url) {
  if (url.indexOf('http://') != -1 || url.indexOf('https://') != -1 || url.indexOf('data:image') != -1) {
    return url;
  }
  url = '//' + szoa.client.domain + url;
  return url;
}

//文件类型缩图,在库里选择时--大图
function file_select(d) {
  switch (d.file_ext) {
    case 'jpg':
    case 'png':
    case 'gif':
    case 'bmp':
    case 'ico':
      return '<a href="javascript:void(0);" onclick=viewImage("' + reurl(d.url) + '")><img src="' + reurl(d.url) + '"/></a>';
      break;
    case 'avi':
    case 'mp3':
    case 'mp4':
    case 'wav':
      return '<a href="javascript:void(0);" onclick=viewVideo("' + reurl(d.url) + '")><i class="fa fa-file-video-o file_table_i"></i></a>';
      break;
    case 'zip':
      return '<a href="javascript:void(0);"><i class="fa fa-file-zip-o file_table_i"></i></a>';
      break;
    case 'txt':
      return '<a href="javascript:void(0);"><i class="fa fa-file-text-o file_table_i"></i></a>';
      break;
    case 'doc':
    case 'docx':
      return '<a href="javascript:void(0);"><i class="fa fa-file-word-o file_table_i"></i></a>';
      break;
    case 'xls':
    case 'xlsx':
      return '<a href="javascript:void(0);"><i class="fa fa-file-excel-o file_table_i"></i></a>';
      break;
    case 'ppt':
    case 'pptx':
      return '<a href="javascript:void(0);"><i class="fa fa-file-powerpoint-o file_table_i"></i></a>';
      break;
    case 'pdf':
      return '<a href="javascript:void(0);" onclick=viewPdf("' + reurl(d.url) + '")><i class="fa fa-file-pdf-o file_table_i"></i></a>';
      break;
  }
  return '';
}

//存储引擎1=本地2=阿里3=微信4=七牛云5=其它...
function storage_engineTd(d) {
  switch (d.storage_engine) {
    case 1:
      return '<span class="layui-badge layui-bg-green">本地</span>';
      break;
    case 2:
      return '<span class="layui-badge layui-bg-blue">阿里云</span>';
      break;
    case 3:
      return '<span class="layui-badge layui-bg-blue">腾讯云</span>';
      break;
    case 4:
      return '<span class="layui-badge layui-bg-blue">七牛云</span>';
      break;
    case 5:
      return '<span class="layui-badge layui-bg-black">其它</span>';
      break;
  }
}

//返回类型1=文件2=图片
function type_img_file(d) {
  if (d != undefined && d != null && d != '') {
    var img = 'jpg,png,gif,bmp,ico';
    var f = d.split('.');
    var x = f.length - 1;
    if (img.indexOf(f[x]) != -1) {
      return 2;
    };
  }
  return 1;
}

function viewPdf(url) {
  top.layui.layer.open({
    type: 2,
    title: false,
    content: url,
    area: ['95%', '95%']
  });
}

//文件类型缩图,在库里选择时--大图
function viewFiles(d) {
  var url = d.url;
  var f = url.split('.');
  var x = f.length - 1;
  var ext = f[x];
  var ops = {
    type: 1,
    title: false,
    content: '',
    area: ['95%', '95%']
  };
  switch (ext) {
    case 'avi':
    case 'mp4':
      ops = {
        type: 1,
        title: false,
        scrollbar: false,
        maxWidth: 960,
        maxHeight: 640,
        skin: 'layui-layer-nobg', //没有背景色
        shadeClose: true,
        content: '<video src="' + url + '" width="960" height="640" controls muted autoplay="autoplay">您的浏览器不支持</video>',
      };
      break;
    case 'mp3':
    case 'wav':
      ops = {
        type: 1,
        title: false,
        scrollbar: false,
        maxWidth: 300,
        maxHeight: 120,
        skin: 'layui-layer-nobg', //没有背景色
        shadeClose: true,
        content: '<audio src="' + url + '" controls>您的浏览器不支持</audio>',
      };
      break;
    case 'zip':
      ops.area = ['300px', '120px'];
      ops.shadeClose = true,
        ops.content = '不支持预览zip压缩文件';
      break;
    case 'txt':
    case 'doc':
    case 'docx':
    case 'xls':
    case 'xlsx':
    case 'ppt':
    case 'pptx':
    case 'pdf':
      ops.type = 2;
      ops.content = url;
      break;
  }
  top.layui.layer.open(ops);
}